<%-- 
    Document   : shoppingCart
    Created on : Sep 4, 2013, 2:23:36 PM
    Author     : Thai Ha Cong
--%>

<%@page import="cart.ShoppingCartItem"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type='text/javaScript'>
            function checkedAll () {
                var inputs = document.getElementsByTagName('input');
                var checkboxes = [];
                var check = document.getElementById('mainCheckbox').checked
                        //.checked
                 
                for (var i = 0; i < inputs.length; i++) {
                if (inputs[i].type == 'checkbox') {
                    inputs[i].checked = check;
                    }
                }
            }
        </script>
        <title>Shopping Cart</title>
        <link href="<%= request.getContextPath()%>/css/style.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
        <div class="headerbg">
            <%@include file="include/iHeader.jsp" %>
        </div>
        <div class="contentbg">
            <div class="shoppingCart">
                <%
                    String emptyMessage;
                    if (scart == null) {
                        emptyMessage = "Empty Shopping Cart.";
                %>
                <div class="uniqueMessage">
                    <p><% out.print(emptyMessage);%></p>
                </div>
                <%
                } else if (scart.getTotalQuantity() == 0) {
                    emptyMessage = "Empty Shopping Cart.";
                %>
                <div class="uniqueMessage">
                    <p><% out.print(emptyMessage);%></p>
                </div>
                <%
                } else {
                %>
                <div class="itemsOnCart">
                    <table>
                        <s:form action="updateShoppingCart" method="POST">
                            <thead>
                                <tr>
                                    <th class="cQty">Quantity</th>
                                    <th class="cRem"><input type="checkbox" id="mainCheckbox" name="check/uncheck all" onclick='checkedAll();'/></th>
                                    <th class="cDes">Product Description</th>
                                    <th class="cPri">Price</th>
                                    <th class="cTot">Total Price</th>
                                </tr>
                            </thead>
                            <tbody>
                                <%
                                    List<ShoppingCartItem> itemsOnCart = scart.getShoppingCartItemList();

                                    for (int i = 0; i < itemsOnCart.size(); i++) {
                                        ShoppingCartItem item = itemsOnCart.get(i);
                                %>
                                <tr>
                                    <td class="cQty"><input type="text" name="newQuantity[<%out.print(i);%>]" value="<% out.print(item.getQuantity());%>" size="2"/></td>
                                    <td class="cRem"><input type="checkbox" name="isRemove[<%out.print(i);%>]"/></td>
                                    <!--value="<% out.print(item.getProduct().getIdProduct());%>"-->
                                    <td class="cDes">
                                        <div class="productTinyImage">
                                            <img src="<% out.print(item.getProduct().getImageurl());%>" alt="<% out.print(item.getProduct().getName());%>" width="64" height="auto">
                                        </div>
                                        <div class="productInfoCart">
                                            <a href="<%= request.getContextPath()%>/product/<% out.print(item.getProduct().getIdProduct());%>/<% out.print(item.getProduct().getName().replace(" ", "-"));%>" title="<% out.print(item.getProduct().getName());%>">
                                                <% out.print(item.getProduct().getName());%>
                                            </a>
                                        </div>
                                    </td>
                                    <td class="cPri">$<% out.print(item.getPrice());%></td>
                                    <td class="cTot">$<% out.print(item.getPrice() * item.getQuantity());%></td>
                                </tr>
                                <%                                            }
                                %>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <td class="cQty">
                                        <s:submit name="button" value="Update" cssStyle="display: inline; width: 76px" theme="simple"/>
                                    </td>
                                    <td class="cRem">
                                        <s:submit name="button" value="Remove" cssStyle="display: inline; width: 76px" theme="simple"/>
                                    </td>
                                    <td class="cDes"><s:actionerror theme="simple"/></td>
                                    <td class="cPri"><b>Subtotal:</b></td>
                                    <td class="cTot">$<% out.print(scart.getTotalAmount());%></td>
                                </tr>
                            </tfoot>
                        </s:form>
                    </table>
                </div>

                <div class="buttonOnShoppingCart">
                    <div class="buttonContinue">
                        <a href="<%= request.getContextPath()%>">Continue Shopping</a>
                    </div>

                    <div class="paypal">
                        <s:form action="setExpressCheckout" namespace="/" method="post">
                            <s:set var="contextPath"><%= request.getContextPath()%></s:set>
                            <s:submit type="image" src="%{contextPath}/css/express-checkout.png" theme="simple" title="Express Checkout with PayPal"  alt="PayPal - The safer, easier way to pay!" cssStyle="vertical-align: middle;"/>
                        </s:form>
                    </div>
                    <div class="buttonProcess" style="background-color: gainsboro">
                        <s:url action="processOrder" var="processOrderUrl" ></s:url>
                        <s:a href="%{processOrderUrl}" >Process Order</s:a>
                    </div>
                </div>
                <%                        }
                %>
            </div>
        </div>
    </div>
    <div class="footerbg">
        <%@include file="include/iFooter.jsp" %>
    </div>
</body>
</html>

